package cz.muni.fi.pa036is.utilities;

import cz.muni.fi.pa036is.entity.Round;
import cz.muni.fi.pa036is.entity.Season;
import java.util.List;
import org.springframework.stereotype.Service;

@Service
public class ScoreCalculationService {

    public String calculateFinalScore(final Long matchId, final Season season,
            final List<Round> roundList) {
        
								int player1Score = 0;
								int player2Score = 0;
								
								for (Round r: roundList) {
												
												player1Score += r.getPointCount1();
												player2Score += r.getPointCount2();
								}
								
								switch (season.getVictoryCondition()) {
												case 1: { // podla vyhry
																if (player1Score == player2Score) {
																				return season.getPointsForDraw() + " : " + season.getPointsForDraw();
																}
																
																return player1Score > player2Score ?
																								(season.getPointsForWin() + " : " + season.getPointsForLose()) :
																								(season.getPointsForLose() + " : " + season.getPointsForWin());
												}
												default: // podla poctu bodov
												{
																return player1Score + " : " + player2Score;
												}
								}
    }

}
